import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Card, Space, Button } from 'antd';
import { ArrowLeftOutlined } from '@ant-design/icons';
import { contestService } from '@/services/contestService';
import styles from './Create.module.css';
import ContestForm from './components/ContestForm';
import { message } from 'antd';

const ContestCreate: React.FC = () => {
  const navigate = useNavigate();
  const [loading, setLoading] = useState(false);

  const handleSubmit = async (values: any) => {
    try {
      setLoading(true);
      await contestService.createContest(values);
      message.success('创建成功');
      navigate('/admin/contest/list');
    } catch (error) {
      message.error('创建失败');
    } finally {
      setLoading(false);
    }
  };

  const handleCancel = () => {
    navigate('/admin/contest/list');
  };

  return (
    <div className={styles.container}>
      <Card>
        <div className={styles.header}>
          <Space>
            <Button 
              icon={<ArrowLeftOutlined />} 
              onClick={() => navigate('/admin/contest/list')}
            >
              返回列表
            </Button>
            <h2>创建比赛</h2>
          </Space>
        </div>
        
        <ContestForm 
          onFinish={handleSubmit}
          onCancel={handleCancel}
          loading={loading}
          submitText="创建"
          cancelText="取消"
        />
      </Card>
    </div>
  );
};

export default ContestCreate; 